package com.jusda.message.producer.strategy;

import com.jusda.message.producer.AsyncProducerStrategy;
import com.jusda.message.producer.SyncProducerStrategy;
import com.jusda.utils.ApplicationContextUtil;

import java.util.HashMap;

/**
 * @author:y022 25/04/2022 23:07
 * @description:
 */
public class ProducerStrategyContext {


    private static final HashMap<String, ProducerStrategy> strategyContainer = new HashMap<>(4);

    static {
        AsyncProducerStrategy bean = ApplicationContextUtil.getApplicationContext().getBean(AsyncProducerStrategy.class);
        System.out.println("bean!!" + bean);
        strategyContainer.put("SYNC", bean);
        strategyContainer.put("ASYNC", ApplicationContextUtil.getApplicationContext().getBean(SyncProducerStrategy.class));
    }


    public static ProducerStrategy selectSendMode(SendMode sendMode) {
        return strategyContainer.get(sendMode.toString());
    }
}
